<template>
  <div class="app-container">
    <div v-show="!detailInfo.visible && !assetDetailInfo.visible">
      <!-- 条件栏 -->
      <div class="filter-wrapper">
        <NewPageFilter
          v-model:query="filterInfo.query"
          :filter-list="filterInfo.list"
          :filter-btn="filterInfo.btn"
        >
          <template v-slot:filter-operateTime>
            <el-date-picker
              v-model="operateTime"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              type="daterange"
              range-separator="至"
              :clearable="true"
              :picker-options="$fn.pickerOptionsFn()"
              align="right"
              start-placeholder="日期开始日期"
              end-placeholder="日期结束日期"
              :shortcuts="$fn.pickerOptionsFn()"
              :default-time="[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 1, 1, 23, 59, 59),
              ]"
              @change="timeChange"
            ></el-date-picker>
          </template>
        </NewPageFilter>
      </div>
      <div class="filter-wrapper">
        <NewPageFilter :filter-btn="filterInfo.btnList"> </NewPageFilter>
      </div>

      <!-- 表格 -->
      <TableContainer
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        :query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        @pageInfo="pageInfo"
      >
        <template v-slot:col-assetCode="scope">
          <span
            v-if="scope.row.assetCode"
            class="slip-edit"
            @click="showDetails(scope.row)"
            >{{ scope.row.assetCode }}</span
          >
          <span v-else>-</span>
        </template>
      </TableContainer>
    </div>
    <!-- 明细信息-预留 -->
    <Detail
      v-if="detailInfo.visible"
      v-model:visible="detailInfo.visible"
      :id="detailInfo.id"
      @returnBack="getList"
    />
    <AssetCardDetail
      v-if="assetDetailInfo.visible"
      :id="assetDetailInfo.id"
      v-model:visible="assetDetailInfo.visible"
      @returnBack="getList"
    />
    <ExcelOrPrint :excelPrint="excelPrint"></ExcelOrPrint>
  </div>
</template>

<script setup name="assetEquipmentRevenue">
import { getAssetIncomeDataPage, excelAssetIncomeData } from '@/api/asset'
import { getDeptAll } from '@/api/core'
const Detail = defineAsyncComponent(() => import('./detail'))
const AssetCardDetail = defineAsyncComponent(() =>
  import('@/views/asset/assetManage/assetCard/details')
)
const { proxy } = getCurrentInstance()

const operateTime = ref([])
// 过滤相关配置
const filterInfo = ref({
  query: {
    sort: 'create_time desc',
    deptAuth: 'id',
  },
  copyQuery: {},
  list: [
    {
      slot: true,
      label: '起止日期',
      value: 'operateTime',
    },
    {
      componentType: 'input',
      label: '资产名称',
      value: 'assetNameLike',
      event: search,
    },
    {
      componentType: 'input',
      label: '资产卡片号',
      value: 'assetCodeLike',
      event: search,
    },
    {
      componentType: 'input',
      label: '厂家',
      value: 'brandNameLike',
      event: search,
    },
    {
      label: '使用部门',
      value: 'useDeptIdMult',
      query: {
        deptAuth: 'id',
        status: 1,
      },
      api: getDeptAll,
      componentType: 'slip-select',
      multiple: true,
      event: search,
    },
    {
      label: '管理部门',
      value: 'manageDeptIdMult',
      query: {
        deptAuth: 'id',
        status: 1,
      },
      api: getDeptAll,
      componentType: 'slip-select',
      multiple: true,
      event: search,
    },
    {
      componentType: 'input',
      label: '项目编码',
      value: 'projectCodeLike',
      event: search,
    },
    {
      componentType: 'input',
      label: '项目名称',
      value: 'projectNameLike',
      event: search,
    },
    {
      asValue: 'dataSourceMult',
      componentType: 'select-model',
      code: 'data_source',
      label: '数据来源',
      event: search,
      multiple: true,
    },
  ],
  btn: [
    { type: 'button', label: '搜索', event: search },
    { type: 'button', label: '重置', event: clearSearch },
  ],
  btnList: [
    {
      type: 'button',
      label: '导出excel',
      event: exportExcel,
      show: proxy.$permission('assetEquipmentRevenue:exportExcel'),
    },
  ],
})
// 表格相关
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  api: getAssetIncomeDataPage,
  data: [],
  selections: [],
  fieldList: [
    {
      label: '日期',
      value: 'incomeDate',
    },
    {
      label: '资产卡片号',
      value: 'assetCode',
      type: 'slot',
    },
    { label: '资产名称', value: 'assetName' },
    { label: '规格', value: 'standard' },
    { label: '厂家', value: 'brandName' },
    { label: '使用部门', value: 'useDeptName' },
    { label: '管理部门', value: 'manageDeptName' },
    { label: '项目编码', value: 'projectCode' },
    { label: '项目名称', value: 'projectName' },
    { label: '数据来源', value: 'dataSourceValue' },
    { label: '申请科室', value: 'makeDeptName' },
    { label: '开单医生', value: 'makeDoctor' },
    { label: '执行科室', value: 'executeDeptName' },
    { label: '执行医生', value: 'executeDoctor' },
    { label: '检查(治疗)人次', value: 'checkTime' },
    { label: '阳性人次', value: 'positiveTime' },
    { label: '收入费用', value: 'income' },
    { label: '开机时长', value: 'powerUp' },
  ],
})
const detailInfo = ref({
  visible: false,
  id: '',
})
const assetDetailInfo = ref({
  visible: false,
  id: '',
})
//打印
const excelPrint = ref({
  type: 'print', // 类型print/excel
  excel: {
    api: excelAssetIncomeData, // 导出数据接口
    params: {}, // 导出参数
  },
  refresh: null,
})
const page = ref({
  page: true,
  pageSize: 20,
  curPage: 1,
})

onMounted(() => {
  filterInfo.value.copyQuery = proxy.$fn.deepClone(filterInfo.value.query)
})

function timeChange(val) {
  if (val && val.length) {
    filterInfo.value.query.startDate = val[0]
    filterInfo.value.query.endDate = val[1]
  } else {
    filterInfo.value.query.startDate = ''
    filterInfo.value.query.endDate = ''
  }
  search()
}
function returnModify() {
  getList()
}
// 获取列表
function getList() {
  tableInfo.value.refresh = Math.random()
}
function clearSearch() {
  filterInfo.value.query = proxy.$fn.deepClone(filterInfo.value.copyQuery)
  operateTime.value = []
  search()
}
// 搜索
function search() {
  // 重置分页
  tableInfo.value.initCurpage = Math.random()
  tableInfo.value.refresh = Math.random()
}
function pageInfo(obj) {
  page.value = obj
}
//导出
function exportExcel() {
  excelPrint.value.type = 'excel'
  excelPrint.value.excel.params = proxy.$fn.deepClone({
    ...proxy.$fn.delEmptyAttribute(filterInfo.value.query),
    ...page.value,
  })
  excelPrint.value.refresh = Math.random()
}
function showDetails(row) {
  if (row.assetId && row.assetId !== -2) {
    assetDetailInfo.value.id = row.assetId
    assetDetailInfo.value.visible = true
  }
}
</script>

<style scoped></style>
